import { Component, OnInit } from "@angular/core";
import { PostService } from "../post.service";
import { ActivatedRoute } from "@angular/router";

@Component({
  selector: "app-post-detail",
  templateUrl: "./post-detail.component.html",
  styleUrls: ["./post-detail.component.scss"]
})
export class PostDetailComponent implements OnInit {
  public post: any = {};

  constructor(
    private postDetailService: PostService,
    public activatedRoute: ActivatedRoute
  ) {}

  ngOnInit(): void {
    this.activatedRoute.params.subscribe(params => this.getPost());
  }

  public getPost(): void {
    this.postDetailService.getPostDetail().subscribe(
      res => {
        this.post = res;
      },
      err => console.log(err)
    );
  }
}
